<?php
	//判断当前用户是否创建团队 
	class CreatTeamModel extends Model{
		public $iscreatteam;
		public $newteam;		//最新团队 
		public $hotteam;		//热门评论团队
		public $mostvoteteam;	//投票最多团队
		public $mostteacher;	//最新评论老师/教官
		
		
		public function __construct(){
			parent::__construct();
			$this->iscreatteam = $this->getiscreatteam();
			$this->newteam = $this->getnewteam();
			$this->hotteam = $this->gethotteam();
			$this->mostvoteteam = $this->getmostvoteteam();
			$this->mostteacher = $this->getmostteacher();
			
		}
		
		private function getiscreatteam(){
			$res=M()->query('
						SELECT t.Captain
						FROM team t
						WHERE t.Captain='.$_SESSION[C('USER_AUTH_KEY')]['UserId']);
			if($res){
				return 1;
			}else{
				return 0;
			}
		}
		
		private function getnewteam(){
			$res = M()->query('
						SELECT Id,Name,Logo
						FROM team
						ORDER BY CraeteDate DESC
						LIMIT 12
					');
			return $res;
		}
		
		private function gethotteam(){
			$res = M()->query('
						SELECT t.Id,t.Name,t.Logo,count(p.CommentCount) as num
						FROM team t,project p
						WHERE t.Id=p.TeamId
						GROUP by t.Id
						ORDER BY num desc
						LIMIT 12
					');
			return $res;
		}
		
		private function getmostvoteteam(){
			$res = M()->query('
						SELECT Id,Name,Logo
						FROM team
						ORDER BY Poll DESC
						LIMIT 12
					');
			return $res;
		}
		
		private function getmostteacher(){
			$res = M()->query('
						SELECT u.UserId,u.TrueName,u.Avatar
						FROM users u,projectcomment p
						WHERE u.UserId=p.UserId
						GROUP BY p.UserId
						ORDER BY p.CreateDate DESC
						LIMIT 12
					');
			return $res;
		}
		
		
	}
	
?>
